package com.yidu.hbatsams.action.TrainingPlan.zxr;


import com.yidu.hbatsams.domain.AtsPlanCurriculum;
import com.yidu.hbatsams.domain.AtsPlanWeek;
import com.yidu.hbatsams.service.TrainingPlan.zxr.AtsCurriculumService;
import com.yidu.hbatsams.service.TrainingPlan.zxr.AtsWeekService;
import com.yidu.hbatsams.utils.Message;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 朱星润
 * @类的描述——周计划Controller
 * @date 2019/10/30下午 04:01
 */
@Controller
@RequestMapping("atsWeekController")
public class AtsWeekController {
    @Resource
    AtsWeekService atsWeekService;//周计划
    @Resource
    AtsCurriculumService atsCurriculumService;//课计划

    /**
     * 分页查所有
     * @param request
     * @param atsWeek
     * @param pageNum
     * @param pageSize
     * @return
     */
    @RequestMapping("selectAll")
    @ResponseBody
    public Map<String, Object> selectAll(HttpServletRequest request, AtsPlanWeek atsWeek, @RequestParam("page") Integer pageNum, @RequestParam("limit") Integer pageSize) {
        List<AtsPlanWeek> list = atsWeekService.selectAll(request, atsWeek, pageNum, pageSize);
        int count = atsWeekService.count(request, atsWeek);
        Map<String, Object> map = new HashMap<>();

        map.put("data", list);
        map.put("count", count);
        map.put("code", 0);
        map.put("msg", "");//消息

        return map;
    }

    /**
     *逻辑删除
     * @param weekId
     * @return
     */
    @RequestMapping("del")
    @ResponseBody
    public Message detele(Integer weekId) {
        //课计划
        int rows = atsWeekService.isvaDel(weekId);

        Message mes = new Message();
        if (rows >= 1) {
            mes.setNum(1);
            mes.setMsg("删除成功");
        } else {
            mes.setNum(0);
            mes.setMsg("删除失败");
        }
        return mes;
    }

    /**
     * 逻辑删除全部
     * @param id
     * @return
     */
    @RequestMapping("delAll")
    @ResponseBody
    public Message delAll(String id) {

        String[] ids = id.split(",");
        int rows = 0;

        for (int i = 0; i < ids.length; i++) {
            atsWeekService.isvaDel(Integer.valueOf(ids[i]));
            rows++;
        }

        Message mes = new Message();
        if (rows >= 1) {
            mes.setNum(1);
            mes.setMsg("删除成功");
        } else {
            mes.setNum(0);
            mes.setMsg("删除失败");
        }
        return mes;
    }

    /**
     * 统计图复选框
     * @param request
     * @param atsWeek
     * @return
     */
    @RequestMapping("comboBox")
    @ResponseBody
    public List<AtsPlanWeek> comboBox(HttpServletRequest request, AtsPlanWeek atsWeek) {

        return atsWeekService.comboBox(request, atsWeek);
    }

    /**
     * 周计划统计图
     * @param request
     * @param ids
     * @param map
     * @return
     */
    @RequestMapping("weekEchar")
    @ResponseBody
    public List<AtsPlanCurriculum> weekEchar(HttpServletRequest request, String ids, Map<String, Object> map) {
        String[] id = ids.split(",");
        map.put("ids", id);
        List<AtsPlanCurriculum> list = atsCurriculumService.weekEchar(request, map);
        return list;

    }

    /**
     * 周计划id查询
     * @param weekId
     * @return
     */
    @RequestMapping("findById")
    @ResponseBody
    public Map<String, Object> findByWeekId(Integer weekId) {
        AtsPlanWeek week = atsWeekService.findById(weekId);

        List<AtsPlanWeek> athleteName = atsWeekService.weekOrAthleteById(weekId);
        List<AtsPlanCurriculum> cur = atsCurriculumService.findByWeekId(weekId);
        Map<String, Object> map = new HashMap<>();
        map.put("data", week);//周计划
        map.put("athleteName", athleteName);//运动员
        map.put("cur", cur);//课计划
        return map;
    }

}
